package com.zhouyibike.uu.ui.activity.hehuoren;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import com.zhouyibike.uu.R;
import com.zhouyibike.uu.config.Config;
import com.zhouyibike.uu.entity.Hehuorenpic;
import com.zhouyibike.uu.http.ApiCallback;
import com.zhouyibike.uu.ui.activity.mybike.Imagesee.ImagePagerActivity;
import com.zhouyibike.uu.ui.activity.mybike.Imagesee.ImagePagerActivity2;
import com.zhouyibike.uu.ui.activity.mybike.MybikeActivity6;
import com.zhouyibike.uu.ui.activity.mybike.RengouActivity;
import com.zhouyibike.uu.ui.adapter.HehuorenjieshaoAdapter;
import com.zhouyibike.uu.ui.base.BaseActivity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class DanchehehuorenxiangqingActivity extends BaseActivity {
    private ImageButton mBtnBack;
    private TextView mBtnTitle;
    private ListView lv;
    private HehuorenjieshaoAdapter adapter;
    private ArrayList<String>imgs=new ArrayList<>();
    private TextView textView2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_danchehehuorenxiangqing);
        initview();
        getMsg();
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (imgs!=null&&imgs.size()>0) {
                    Intent intent = new Intent(DanchehehuorenxiangqingActivity.this, ImagePagerActivity2.class);
                    // 图片url,为了演示这里使用常量，一般从数据库中或网络中获取
                    intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, (Serializable) imgs);
                    intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, i );
                    startActivity(intent);
                }}
        });
        textView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(DanchehehuorenxiangqingActivity.this, RengouActivity.class);
                startActivityForResult(intent,200);
            }
        });
    }

    private void initview() {
        lv= (ListView) findViewById(R.id.danchehehuoren_lv);
        mBtnBack = (ImageButton) findViewById(R.id.bar_btn_back);
        mBtnTitle = (TextView) findViewById(R.id.bar_text_title);
        mBtnTitle.setText("单车合伙人");
        textView2= (TextView) findViewById(R.id.textView2);
    }
    //单车合伙人pic
    private void getMsg() {
        Map<String, String> params = new HashMap<>();
        params.put("token", preferences.getString("token", ""));
//        showProgressDialog();
        addSubscription(apiStores.BikeCompanyInterface(params),
                new ApiCallback<Hehuorenpic>() {
                    @Override
                    public void onSuccess(Hehuorenpic model) {
                        if (model.getStatus() == Config.SUCCESSCODE) {
                            imgs.clear();
                            for (int i = 0; i <model.getData().size() ; i++) {
                                imgs.add(model.getData().get(i).getImagePath());
                            }
                            adapter=new HehuorenjieshaoAdapter(DanchehehuorenxiangqingActivity.this,model.getData());
                        } else {
                            toastShow(model.getMessage());
                        }
                    }

                    @Override
                    public void onFailure(String msg) {
                        toastShow(msg);
                    }
                    @Override
                    public void onFinish() {
                        if (adapter!=null)
                        {
                            lv.setAdapter(adapter);
                        }
                    }
                });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==200&&resultCode==789)
        {
            Intent i=new Intent(this,MybikeActivity6.class);
            startActivity(i);
        }
    }
}
